package com.woniuxy.dynamic.cglib;

import com.woniuxy.dynamic.aspect.LogForService;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

/**
 * @author 佘赛飞
 * @create 2021 -11 -15 7:18 PM
 */
public class CgliDynamic {

    public Object getProxyObject(final Object targetClass) {
        Object o = Enhancer.create(targetClass.getClass(), new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                LogForService logForService = new LogForService();
                logForService.beforeStrengthen();
                Object invoke = method.invoke(targetClass, args);
                logForService.afterStrengthen();
                return invoke;

            }
        });
        return o;
    }
}
